
package com.wobaby.util.log;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.wobaby.util.config.Config;

// Referenced classes of package com.wobaby.util.log:
//            LogPrinter, DefaultLogPrinter

public class Log
{

    public static LogPrinter getLog(String name)
    {
        name = name.toLowerCase();
        LogPrinter lp = (LogPrinter)s_logMap.get(name);
        if(lp == null)
        {
            System.out.println("WARNING: Log.getLog(): Creating log for " + name);
            lp = new DefaultLogPrinter(name);
            s_logMap.put(name, lp);
        }
        return lp;
    }

    public static String getLevelName(int id)
    {
        return (String)s_valueMap.get(new Integer(id));
    }

    public static Map getLevelsMap()
    {
        return s_valueMap;
    }

    private Log()
    {
    }

    public static final int LEVEL_NONE = 100;
    public static final int LEVEL_FATAL = 99;
    public static final int LEVEL_ASSERT = 90;
    public static final int LEVEL_ERROR = 75;
    public static final int LEVEL_WARNING = 50;
    public static final int LEVEL_INFO = 25;
    public static final int LEVEL_DEBUG = 10;
    public static final int LEVEL_TRACE = 0;
    private static Map s_logMap;
    private static Map s_valueMap;
    private static final boolean DEBUG = false;

    static 
    {
        boolean showLogCreation = Config.getConfig().get("show_log_creation", false);
        s_valueMap = new HashMap();
        s_valueMap.put(new Integer(100), "None");
        s_valueMap.put(new Integer(99), "Fatal");
        s_valueMap.put(new Integer(75), "Error");
        s_valueMap.put(new Integer(90), "Assert");
        s_valueMap.put(new Integer(50), "Warning");
        s_valueMap.put(new Integer(25), "Info");
        s_valueMap.put(new Integer(10), "Debug");
        s_valueMap.put(new Integer(0), "Trace");
        s_logMap = new HashMap();
        Set s = Config.getConfig().getKeySet("log/");
        Iterator iter = s.iterator();
        int count = 0;
        do
        {
            if(!iter.hasNext())
                break;
            String key = (String)iter.next();
            if(!key.endsWith("/level"))
            {
                String logName = key.substring(4);
                if(showLogCreation)
                    System.out.println("Log.<init>: Creating log for " + logName);
                LogPrinter lp = new DefaultLogPrinter(logName);
                s_logMap.put(logName, lp);
                count++;
            }
        } while(true);
        if(showLogCreation)
            System.out.println("Log.<init>: Created " + count + " DefaultLogPrinters");
    }
}